﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Contracts;
using ViewModel;

namespace View
{
	/// <summary>
	/// Logique d’interaction pour WindowDiscussion.xaml
	/// </summary>
	public partial class WindowDiscussion : Window
	{
        protected DiscussionContainerViewModel ViewModel { get; set; }
		public WindowDiscussion()
		{
			InitializeComponent();

            
			
            // Create the viewModel containing our discussions
            this.ViewModel = DiscussionContainerViewModel.getInstance();

		    this.DataContext = this.ViewModel;
		}

        private void buttonClosingTab_Click(object sender, RoutedEventArgs e)
        {
           
            this.ViewModel.CloseDiscussionCommand.Execute(getCurrentContact());

            if(tabControlDiscussion.Items.Count.Equals(0))
            {
                Close();
            }
        }
        
        private DiscussionViewModel getCurrentDiscussion()
        {
            return this.tabControlDiscussion.SelectedItem as DiscussionViewModel;
        }
        private Contact getCurrentContact()
        {
            return this.getCurrentDiscussion().CurrentContact;
        }

        private void buttonSendMessage_Click(object sender, RoutedEventArgs e)
        {
            this.ViewModel.SendMessageCommand.Execute(getCurrentContact());
        }
	}
}